package com.bdf.ipharma.gui;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;

import com.bdf.ipharma.ApplicationContextProvider;
import com.bdf.ipharma.model.Usuario;




/**
 *
 * @author edw
 */
public class SignUp extends JFrame implements ActionListener {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField txtNama = new JTextField();
    private JTextField txtAlamat = new JTextField();
    private JButton cmdButton = new JButton("Save");
    private Logger logger = Logger.getLogger(SignUp.class);

    public SignUp() {
        setLayout(new GridLayout(3, 3));
        Container con = this.getContentPane();
        con.add(new JLabel("nama : "));
        con.add(txtNama);
        con.add(new JLabel("Alamat : "));
        con.add(txtAlamat);
        con.add(cmdButton);

        cmdButton.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == cmdButton) {
            Usuario user = new Usuario();
            user.setUsername(txtNama.getText());
            user.setPassword(txtAlamat.getText());

            try {
                ApplicationContext ac = ApplicationContextProvider.getInstance().getApplicationContext();
//                ContohService service = (ContohService) ac.getBean("contohService");
//                service.insert(user);
                logger.debug("success");
            } catch (Exception ex) {
                logger.error(ex.getMessage(), ex);
            }
        }
    }

    public static void main(String[] args) {
    	SignUp signUp = new SignUp();
        signUp.setVisible(true);
        signUp.setSize(300, 150);
        signUp.setLocationRelativeTo(null);
    }
}

